/**
 * 
 */
package us.gaaoc.framework.webapp.backingbeans;



import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UISelectOne;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.faces.validator.ValidatorException;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.jfree.util.Log;

import us.gaaoc.framework.dao.CaseRecordHistoryDAO;
import us.gaaoc.framework.dao.DAOFactory;
import us.gaaoc.framework.logic.validation.DateValidationLogic;
import us.gaaoc.framework.model.CaseRecord;
import us.gaaoc.framework.model.DocumentInstance;
import us.gaaoc.framework.model.Person;
import us.gaaoc.framework.model.Roles;
import us.gaaoc.framework.util.io.FileUtility;
import us.gaaoc.framework.util.validators.DateValidator;
import us.gaaoc.framework.webapp.backingbeans.BaseBackingBean;
import us.gaaoc.framework.webapp.util.Messages;

/**
 * @author Rex McElrath
 * Oct 24, 2007
 *
 */
public class ReportSummaryPage extends BaseBackingBean {	

	/**
	 * Date of the starting day of Court for the Court Calendar Report to Pull.
	 */
	private Date startCourtDate;
	/**
	 *  Date of the ending day of Court for the Court Calendar Report to Pull.
	 */
	private Date endCourtDate;
	/**
	 * An array list of the different format types available for a report.
	 * Formats available
	 * <ul>
	 * 	<li> PDF </li>
	 * 	<li> RTF </li>
	 * 	<li> PNG </li>
	 */
	private ArrayList<SelectItem> reportFormatTypeDescriptionItems;
	/**
	 * A user interface input item to hold the currently selected report format
	 * variable.
	 */
	private UISelectOne reportFormatTypeInput;
	/**
	 * A string to hold the value of the report format that is selected.
	 */
	private int reportFormatType;
	/**
	 * Java Server Faces Message component to be used to display error and
	 * informational messages.
	 */
	private FacesMessage message;
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 8905870571068078452L;
	/**
	 * Properties
	 */
	private static final Logger LOG = Logger.getLogger(ReportSummaryPage.class);
	
	
	
	  private String importedCaseFilingCount;
	  private String queuedForImportCaseFilingCount;
	  private String  failedToImportCaseFilingCount;
	  private String clerkRejectedCaseFilingCount;
	  private String attorneyRejectedCaseFilingCount;
	  private String attorneyRecievedCaseFilingCount;
	  private String  attorneyAdditionCaseFilingCount;
	  private String clerkRecievedCaseFilingCount;
	  private String clerkReadyToImportCaseFilingCount;
	  private String unsentCaseFilingCount;
	  private String unsentAdditionCaseFilingCount;
	  private String readyToSendToCourtCaseFilingCount;
	
	
	
	
	/* *************************************************************************
	 * Navigation Methods
	 * *************************************************************************
	 */
	
	/**
	 * Trigger navigation to the System Statistics Page
	 */
	/*public String goToSystemStatistics() {
		return "goToSystemStatistics";
	}
	/**
	 * Trigger navigation to the Personal Statistics Page
	 */
/*	public String goToPersonalStatistics() {
		return "goToPersonalStatistics";
	}*/
	
	
	/* *************************************************************************
	 * Variable Getter and Setter Section
	 * *************************************************************************
	 */
	/**
	 * @return the startCourtDate
	 */
	public Date getStartCourtDate() {
		return startCourtDate;
	}

	/**
	 * @param startCourtDate the startCourtDate to set
	 */
	public void setStartCourtDate(Date startCourtDate) {
		this.startCourtDate = startCourtDate;
	}

	/**
	 * @return the endCourtDate
	 */
	public Date getEndCourtDate() {
		return endCourtDate;
	}

	/**
	 * @param endCourtDate the endCourtDate to set
	 */
	public void setEndCourtDate(Date endCourtDate) {
		this.endCourtDate = endCourtDate;
	}
	
	/**
	 * @return docTypeDescriptionsItems
	 */
	public ArrayList<SelectItem> getReportFormatTypeDescriptionItems() {
		reportFormatTypeDescriptionItems = new ArrayList<SelectItem>();
		//The Latest Action(QueuedForImport/Import/FaileToImport/Uploaded) Taken on a Case lies between the Entered Date Ranges 
		reportFormatTypeDescriptionItems.add(new SelectItem(1, "By Latest Action and Status"));
		// The Cases Created on that Date and What status are they in right now
		reportFormatTypeDescriptionItems.add(new SelectItem(2, "By Instantiation Date"));
		
		reportFormatTypeDescriptionItems.add(new SelectItem(3, "By Latest Case Action"));
		// What Action (uploaded/imported/SendToAttorney...) was commited by the User between that Dates on those Cases and these Case may be on different Status 
		reportFormatTypeDescriptionItems.add(new SelectItem(4, "By Case Status"));
		return reportFormatTypeDescriptionItems;
	}

	public void setReportFormatTypDescriptionItems(ArrayList<SelectItem> si) {
		reportFormatTypeDescriptionItems = si;
	}

	/**
	 * @return the reportFormatTypeInput
	 */
	public UISelectOne getReportFormatTypeInput() {
		return reportFormatTypeInput;
	}

	/**
	 * @param reportFormatTypeInput the reportFormatTypeInput to set
	 */
	public void setReportFormatTypeInput(UISelectOne reportFormatTypeInput) {
		this.reportFormatTypeInput = reportFormatTypeInput;
	}

	/**
	 * @return the reportFormatType
	 */
	public int getReportFormatType() {
		return reportFormatType;
	}

	/**
	 * @param reportFormatType the reportFormatType to set
	 */
	public void setReportFormatType(int reportFormatType) {
		this.reportFormatType = reportFormatType;
	}
	
	
	
	
	
	
	public String getImportedCaseFilingCount() {
		return importedCaseFilingCount;
	}

	public void setImportedCaseFilingCount(String importedCaseFilingCount) {
		this.importedCaseFilingCount = importedCaseFilingCount;
	}

	public String getQueuedForImportCaseFilingCount() {
		return queuedForImportCaseFilingCount;
	}

	public void setQueuedForImportCaseFilingCount(
			String queuedForImportCaseFilingCount) {
		this.queuedForImportCaseFilingCount = queuedForImportCaseFilingCount;
	}

	public String getFailedToImportCaseFilingCount() {
		return failedToImportCaseFilingCount;
	}

	public void setFailedToImportCaseFilingCount(
			String failedToImportCaseFilingCount) {
		this.failedToImportCaseFilingCount = failedToImportCaseFilingCount;
	}

	public String getClerkRejectedCaseFilingCount() {
		return clerkRejectedCaseFilingCount;
	}

	public void setClerkRejectedCaseFilingCount(String clerkRejectedCaseFilingCount) {
		this.clerkRejectedCaseFilingCount = clerkRejectedCaseFilingCount;
	}

	public String getAttorneyRejectedCaseFilingCount() {
		return attorneyRejectedCaseFilingCount;
	}

	public void setAttorneyRejectedCaseFilingCount(
			String attorneyRejectedCaseFilingCount) {
		this.attorneyRejectedCaseFilingCount = attorneyRejectedCaseFilingCount;
	}

	public String getAttorneyRecievedCaseFilingCount() {
		return attorneyRecievedCaseFilingCount;
	}

	public void setAttorneyRecievedCaseFilingCount(
			String attorneyRecievedCaseFilingCount) {
		this.attorneyRecievedCaseFilingCount = attorneyRecievedCaseFilingCount;
	}

	public String getAttorneyAdditionCaseFilingCount() {
		return attorneyAdditionCaseFilingCount;
	}

	public void setAttorneyAdditionCaseFilingCount(
			String attorneyAdditionCaseFilingCount) {
		this.attorneyAdditionCaseFilingCount = attorneyAdditionCaseFilingCount;
	}

	public String getClerkRecievedCaseFilingCount() {
		return clerkRecievedCaseFilingCount;
	}

	public void setClerkRecievedCaseFilingCount(String clerkRecievedCaseFilingCount) {
		this.clerkRecievedCaseFilingCount = clerkRecievedCaseFilingCount;
	}

	public String getClerkReadyToImportCaseFilingCount() {
		return clerkReadyToImportCaseFilingCount;
	}

	public void setClerkReadyToImportCaseFilingCount(
			String clerkReadyToImportCaseFilingCount) {
		this.clerkReadyToImportCaseFilingCount = clerkReadyToImportCaseFilingCount;
	}



	
	public String getReadyToSendToCourtCaseFilingCount() {
		return readyToSendToCourtCaseFilingCount;
	}

	public void setReadyToSendToCourtCaseFilingCount(
			String readyToSendToCourtCaseFilingCount) {
		this.readyToSendToCourtCaseFilingCount = readyToSendToCourtCaseFilingCount;
	}
	
	
	public String getUnsentCaseFilingCount() {
		return unsentCaseFilingCount;
	}

	public void setUnsentCaseFilingCount(String unsentCaseFilingCount) {
		this.unsentCaseFilingCount = unsentCaseFilingCount;
	}

		
	public String getUnsentAdditionCaseFilingCount() {
		return unsentAdditionCaseFilingCount;
	}

	public void setUnsentAdditionCaseFilingCount(
			String unsentAdditionCaseFilingCount) {
		this.unsentAdditionCaseFilingCount = unsentAdditionCaseFilingCount;
	}

	/* *************************************************************************
	 * Logic Invoking Method Section
	 * *************************************************************************
	 */
	/**
	 * Wrapper Method to interface with the date validation utility. 
	 * 
	 * @param context
	 * @param component
	 * @param value
	 * @throws ValidatorException
	 * @throws Exception
	 */
	public void validateDate(FacesContext context, UIComponent component,
			Object value) throws ValidatorException, Exception {
		Date dateToCheck = (Date) value;
		String dateToCheckString = dateToCheck.toString();

		/*
		 * There is a bug in JSF page to pass over a date value, the passed
		 * value is always 1 day behind . The day field of the Calendar object
		 * starts with 1 but the month field starts with 0. This confusion might
		 * be the cause of the bug.
		 * 
		 * 
		 */
		DateValidationLogic dvl = new DateValidationLogic();
		Boolean validDate = dvl.validateMMDDYYYYFormatDate(dateToCheckString);
		if (validDate == false) {
			message = Messages.getMessage(
					"us.gaaoc.framework.webapp.util.errorMessage",
					"incorrectDate", null);
			message.setDetail(message.getDetail());
			message.setSeverity(FacesMessage.SEVERITY_ERROR);
			throw new ValidatorException(message);
		} 
	}
	
	

	
	/**
	 * Method to generate a report and stream it to the browser
	 */
	

  public void generateReport() {
	  System.out.println("I have entered into the generateReport() Method");

	  int clerkrejectedCaseCount=0;
	  int importedCaseCount =0;
	  int queuedforImportCaseCount=0;
	  int failedToImportCaseCount=0;
	  int attorneyRejectedCaseCount=0;
	  int attorneyReceivedCaseCount=0;
	  int attorneyAdditionCaseCount=0;
	  int readyToSendToCourtCaseCount=0;
	  int clerkreceivedCaseCount=0;
	  int readyToImportCaseCount=0;
	  int unsentCaseCount=0;
	  int usentAdditionCaseCount=0;
	  
	  /**
	   * 
	   * ippudu naaku emi emi kavali?
	   * 
	   * Case 1: Status Code and Last Event Date Time
	   * Case 2: Status Code and Creation Date
	   * Case 3: event code and latest event date time
	   * Case 4: event code and event date time
	   * 
	   */
	  
	  
	  Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
	  String CourtUuid = (String) sessionMap.get("courtUuid");
	  Log.warn("The court which the Case belongs to is : "+CourtUuid);
	  Log.warn("The Search Criteria Selected is : "+this.getReportFormatType());
	  sessionMap.put("CourtStartDate", this.getStartCourtDate());
	  sessionMap.put("CourtEndDate", this.getEndCourtDate());
	  sessionMap.put("formatTypeSelected",this.getReportFormatType());

	  
		System.out.println("*******************************************************************************************************");

		System.out.println("The Search Criteria Selected is : "+this.getReportFormatType());

		System.out.println("*******************************************************************************************************");

	  switch (this.getReportFormatType()) {
      case 1:
    	  /**
  	  	 * Queuries by Status it is in and and latest event Date time on that Case
  	  	 * we need to have links to other pages
  	  	 */
           	

    	  clerkrejectedCaseCount =this.getModelFacade().findAllCaseRecordByStatusCodeandLatestEventDateTime(3, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
    	  this.setClerkRejectedCaseFilingCount(Integer.toString(clerkrejectedCaseCount));

    	  importedCaseCount=this.getModelFacade().findAllCaseRecordByStatusCodeandLatestEventDateTime(2, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
    	  this.setImportedCaseFilingCount(Integer.toString(importedCaseCount));

    	  queuedforImportCaseCount=this.getModelFacade().findAllCaseRecordByStatusCodeandLatestEventDateTime(21, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
    	  this.setQueuedForImportCaseFilingCount(Integer.toString(queuedforImportCaseCount));

    	  failedToImportCaseCount=this.getModelFacade().findAllCaseRecordByStatusCodeandLatestEventDateTime(22, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
    	  this.setFailedToImportCaseFilingCount(Integer.toString(failedToImportCaseCount));

			 attorneyRejectedCaseCount=this.getModelFacade().findAllCaseRecordByStatusCodeandLatestEventDateTime(8, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setAttorneyRejectedCaseFilingCount(Integer.toString(attorneyRejectedCaseCount));

			attorneyReceivedCaseCount=this.getModelFacade().findAllCaseRecordByStatusCodeandLatestEventDateTime(10, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setAttorneyRecievedCaseFilingCount(Integer.toString(attorneyReceivedCaseCount));

			attorneyAdditionCaseCount=this.getModelFacade().findAllCaseRecordByStatusCodeandLatestEventDateTime(16, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setAttorneyAdditionCaseFilingCount(Integer.toString(attorneyAdditionCaseCount));

			readyToSendToCourtCaseCount=this.getModelFacade().findAllCaseRecordByStatusCodeandLatestEventDateTime(11, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setReadyToSendToCourtCaseFilingCount(Integer.toString(readyToSendToCourtCaseCount));

			clerkreceivedCaseCount=this.getModelFacade().findAllCaseRecordByStatusCodeandLatestEventDateTime(1, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setClerkRecievedCaseFilingCount(Integer.toString(clerkreceivedCaseCount));

			readyToImportCaseCount=this.getModelFacade().findAllCaseRecordByStatusCodeandLatestEventDateTime(20, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setClerkReadyToImportCaseFilingCount(Integer.toString(readyToImportCaseCount));

			unsentCaseCount = this.getModelFacade().findAllCaseRecordByStatusCodeandLatestEventDateTime(7, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setUnsentCaseFilingCount(Integer.toString(unsentCaseCount));

			usentAdditionCaseCount=this.getModelFacade().findAllCaseRecordByStatusCodeandLatestEventDateTime(15, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setUnsentAdditionCaseFilingCount(Integer.toString(usentAdditionCaseCount));

    	
    	  
    	  
  	break;
      case 2:
    	  	
    	  /**
  	  	 * Queuries by Status Code that has occured and created Date time on that Case
  	  	 */

    	  clerkrejectedCaseCount =this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(3, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
    	  this.setClerkRejectedCaseFilingCount(Integer.toString(clerkrejectedCaseCount));

    	  importedCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(2, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
    	  this.setImportedCaseFilingCount(Integer.toString(importedCaseCount));

    	  queuedforImportCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(21, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
    	  this.setQueuedForImportCaseFilingCount(Integer.toString(queuedforImportCaseCount));

    	  failedToImportCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(22, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
    	  this.setFailedToImportCaseFilingCount(Integer.toString(failedToImportCaseCount));

			 attorneyRejectedCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(8, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setAttorneyRejectedCaseFilingCount(Integer.toString(attorneyRejectedCaseCount));

			attorneyReceivedCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(10, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setAttorneyRecievedCaseFilingCount(Integer.toString(attorneyReceivedCaseCount));

			attorneyAdditionCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(16, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setAttorneyAdditionCaseFilingCount(Integer.toString(attorneyAdditionCaseCount));

			readyToSendToCourtCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(11, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setReadyToSendToCourtCaseFilingCount(Integer.toString(readyToSendToCourtCaseCount));

			clerkreceivedCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(1, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setClerkRecievedCaseFilingCount(Integer.toString(clerkreceivedCaseCount));

			readyToImportCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(20, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setClerkReadyToImportCaseFilingCount(Integer.toString(readyToImportCaseCount));

			unsentCaseCount = this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(7, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setUnsentCaseFilingCount(Integer.toString(unsentCaseCount));

			usentAdditionCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(15, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setUnsentAdditionCaseFilingCount(Integer.toString(usentAdditionCaseCount));

    	  	break;
    
  case 3:
    	  	/**
    	  	 * Queuries by Latest Event that has occured and latest event Date time on that Case
    	  	 * we need to have links to other pages
    	  	 */
    	  

    	  clerkrejectedCaseCount =this.getModelFacade().findAllCaseRecordByEventCodeandLatestEventDateTime(3, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
    	  this.setClerkRejectedCaseFilingCount(Integer.toString(clerkrejectedCaseCount));

    	  importedCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandLatestEventDateTime(2, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
    	  this.setImportedCaseFilingCount(Integer.toString(importedCaseCount));

    	  queuedforImportCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandLatestEventDateTime(26, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
    	  this.setQueuedForImportCaseFilingCount(Integer.toString(queuedforImportCaseCount));

    	  failedToImportCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandLatestEventDateTime(20, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
    	  this.setFailedToImportCaseFilingCount(Integer.toString(failedToImportCaseCount));

			 attorneyRejectedCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandLatestEventDateTime(8, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setAttorneyRejectedCaseFilingCount(Integer.toString(attorneyRejectedCaseCount));

			attorneyReceivedCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandLatestEventDateTime(9, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setAttorneyRecievedCaseFilingCount(Integer.toString(attorneyReceivedCaseCount));

			attorneyAdditionCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandLatestEventDateTime(24, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setAttorneyAdditionCaseFilingCount(Integer.toString(attorneyAdditionCaseCount));

			readyToSendToCourtCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandLatestEventDateTime(10, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setReadyToSendToCourtCaseFilingCount(Integer.toString(readyToSendToCourtCaseCount));

			clerkreceivedCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandLatestEventDateTime(1, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setClerkRecievedCaseFilingCount(Integer.toString(clerkreceivedCaseCount));

			readyToImportCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandLatestEventDateTime(17, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setClerkReadyToImportCaseFilingCount(Integer.toString(readyToImportCaseCount));

			unsentCaseCount = this.getModelFacade().findAllCaseRecordByEventCodeandLatestEventDateTime(12, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setUnsentCaseFilingCount(Integer.toString(unsentCaseCount));

			usentAdditionCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandLatestEventDateTime(13, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setUnsentAdditionCaseFilingCount(Integer.toString(usentAdditionCaseCount));

    	  	break;
    
  case 4:
	  	/**
	  	 * Queuries by  Event that has occured and  event Date time on that Case
	  	 * no links must be provided
	  	 */
	  

	  clerkrejectedCaseCount =this.getModelFacade().findAllCaseRecordByEventCodeandEventDateTime(3, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
	  this.setClerkRejectedCaseFilingCount(Integer.toString(clerkrejectedCaseCount));

	  importedCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandEventDateTime(2, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
	  this.setImportedCaseFilingCount(Integer.toString(importedCaseCount));

	  queuedforImportCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandEventDateTime(26, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
	  this.setQueuedForImportCaseFilingCount(Integer.toString(queuedforImportCaseCount));

	  failedToImportCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandEventDateTime(20, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
	  this.setFailedToImportCaseFilingCount(Integer.toString(failedToImportCaseCount));

		 attorneyRejectedCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandEventDateTime(8, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
		this.setAttorneyRejectedCaseFilingCount(Integer.toString(attorneyRejectedCaseCount));

		attorneyReceivedCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandEventDateTime(9, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
		this.setAttorneyRecievedCaseFilingCount(Integer.toString(attorneyReceivedCaseCount));

		attorneyAdditionCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandEventDateTime(24, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
		this.setAttorneyAdditionCaseFilingCount(Integer.toString(attorneyAdditionCaseCount));

		readyToSendToCourtCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandEventDateTime(10, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
		this.setReadyToSendToCourtCaseFilingCount(Integer.toString(readyToSendToCourtCaseCount));

		clerkreceivedCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandEventDateTime(1, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
		this.setClerkRecievedCaseFilingCount(Integer.toString(clerkreceivedCaseCount));

		readyToImportCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandEventDateTime(17, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
		this.setClerkReadyToImportCaseFilingCount(Integer.toString(readyToImportCaseCount));

		unsentCaseCount = this.getModelFacade().findAllCaseRecordByEventCodeandEventDateTime(12, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
		this.setUnsentCaseFilingCount(Integer.toString(unsentCaseCount));

		usentAdditionCaseCount=this.getModelFacade().findAllCaseRecordByEventCodeandEventDateTime(13, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
		this.setUnsentAdditionCaseFilingCount(Integer.toString(usentAdditionCaseCount));

	  	break;

	  		
    	  	
      default:
    	 	
    	
    	  clerkrejectedCaseCount =this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(3, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
    	  this.setClerkRejectedCaseFilingCount(Integer.toString(clerkrejectedCaseCount));

    	  importedCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(2, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
    	  this.setImportedCaseFilingCount(Integer.toString(importedCaseCount));

    	  queuedforImportCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(21, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
    	  this.setQueuedForImportCaseFilingCount(Integer.toString(queuedforImportCaseCount));

    	  failedToImportCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(22, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
    	  this.setFailedToImportCaseFilingCount(Integer.toString(failedToImportCaseCount));

			 attorneyRejectedCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(8, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setAttorneyRejectedCaseFilingCount(Integer.toString(attorneyRejectedCaseCount));

			attorneyReceivedCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(10, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setAttorneyRecievedCaseFilingCount(Integer.toString(attorneyReceivedCaseCount));

			attorneyAdditionCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(16, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setAttorneyAdditionCaseFilingCount(Integer.toString(attorneyAdditionCaseCount));

			readyToSendToCourtCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(11, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setReadyToSendToCourtCaseFilingCount(Integer.toString(readyToSendToCourtCaseCount));

			clerkreceivedCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(1, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setClerkRecievedCaseFilingCount(Integer.toString(clerkreceivedCaseCount));

			readyToImportCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(20, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setClerkReadyToImportCaseFilingCount(Integer.toString(readyToImportCaseCount));

			unsentCaseCount = this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(7, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setUnsentCaseFilingCount(Integer.toString(unsentCaseCount));

			usentAdditionCaseCount=this.getModelFacade().findAllCaseRecordByStatusandCreatedDate(15, CourtUuid, this.getStartCourtDate(), this.getEndCourtDate()).size();
			this.setUnsentAdditionCaseFilingCount(Integer.toString(usentAdditionCaseCount));

    	  	break;
    
  }
	  
		
  }
	
	public String back() {
		
		Person p = (Person) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("person");
		String ret = "backagent";
		Iterator i = p.getRoles().iterator();
		while(i.hasNext())
		{
			String role= ((Roles) i.next()).getRole();
			System.out.println("The person who logged in : " + role);
			if(role.equalsIgnoreCase("agent"))
			{
				ret="backagent";
			}if(role.equalsIgnoreCase("attorney"))
			{
				ret="backattorney";
			}if(role.equalsIgnoreCase("clerk"))
			{
				ret="backclerk";
			}

		}
		return ret;
		
	}
	
	
	public String gotoImportedCaseFilings()
	{
		  Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
		System.out.println("==============================================================");
		System.out.println("I have click the first Link for the Imported Cases");
		System.out.println("The Format Type selected is : " + sessionMap.get("formatTypeSelected"));
				System.out.println("==============================================================");
		Integer myint = (Integer) sessionMap.get("formatTypeSelected");
		
		
		switch(myint.intValue())
		{
		case 1:
			sessionMap.put("SearchStatusCode", "2");
			break;
		case 2:
			sessionMap.put("SearchStatusCode", "2");
			break;
		case 3:
			sessionMap.put("SearchStatusCode", "2");
			break;
		case 4:
			return "PageInvalid";
		}
		
		return "gotoImportedCaseFilings";
	}
	
	public String gotoQueuedForImportCaseFilings()
	{
		  Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
			System.out.println("==============================================================");
			System.out.println("I have click the first Link for the Queued for Imported Cases");
			System.out.println("The Format Type selected is : " + sessionMap.get("formatTypeSelected"));
			System.out.println("==============================================================");
			Integer myint = (Integer) sessionMap.get("formatTypeSelected");
			
			
			switch(myint.intValue())
			{
			case 1:
				sessionMap.put("SearchStatusCode", "21");
				break;
			case 2:
				sessionMap.put("SearchStatusCode", "21");
				break;
			case 3:
				sessionMap.put("SearchStatusCode", "26");
				break;
			case 4:
				return "PageInvalid";
			}

		return "gotoQueuedForImportCaseFilings";
	}
	
	
	
	public String gotoFailedToImportCaseFilings()
	{
		  Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
			System.out.println("==============================================================");
			System.out.println("I have click the first Link for the Failed to Imported Cases");
			System.out.println("The Format Type selected is : " + sessionMap.get("formatTypeSelected"));
			System.out.println("==============================================================");
			Integer myint = (Integer) sessionMap.get("formatTypeSelected");
			
			
			switch(myint.intValue())
			{
			case 1:
				sessionMap.put("SearchStatusCode", "22");
				break;
			case 2:
				sessionMap.put("SearchStatusCode", "22");
				break;
			case 3:
				sessionMap.put("SearchStatusCode", "20");
				break;
			case 4:
				return "PageInvalid";
			}
		return "gotoFailedToImportCaseFilings";
	}
	
	
	public String gotoAttorneyRejectedCaseFilings()
	{	  
		
	Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
	System.out.println("==============================================================");
	System.out.println("I have click the first Link for Attorney Rejected Cases");
	System.out.println("The Format Type selected is : " + sessionMap.get("formatTypeSelected"));
	System.out.println("==============================================================");
	Integer myint = (Integer) sessionMap.get("formatTypeSelected");
	
	
	switch(myint.intValue())
	{
	case 1:
		sessionMap.put("SearchStatusCode", "8");
		break;
	case 2:
		sessionMap.put("SearchStatusCode", "8");
		break;
	case 3:
		sessionMap.put("SearchStatusCode", "8");
		break;
	case 4:
		return "PageInvalid";
	}

		return "gotoAttorneyRejectedCaseFilings";
	}
	
	
	public String gotoAttorneyReceivedCaseFilings()
	{
		Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
		System.out.println("==============================================================");
		System.out.println("I have click the first Link for Attorney Received Cases");
		System.out.println("The Format Type selected is : " + sessionMap.get("formatTypeSelected"));
		System.out.println("==============================================================");
		Integer myint = (Integer) sessionMap.get("formatTypeSelected");
		
		
		switch(myint.intValue())
		{
		case 1:
			sessionMap.put("SearchStatusCode", "10");
			break;
		case 2:
			sessionMap.put("SearchStatusCode", "10");
			break;
		case 3:
			sessionMap.put("SearchStatusCode", "9");
			break;
		case 4:
			return "PageInvalid";
		}
		return "gotoAttorneyReceivedCaseFilings";
	}
	
	
	public String gotoAttorneyAdditionCaseFilings()
	{
		Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
		System.out.println("==============================================================");
		System.out.println("I have click the first Link for Attorney Addition Cases");
		System.out.println("The Format Type selected is : " + sessionMap.get("formatTypeSelected"));
		System.out.println("==============================================================");
		Integer myint = (Integer) sessionMap.get("formatTypeSelected");
		
		
		switch(myint.intValue())
		{
		case 1:
			sessionMap.put("SearchStatusCode", "16");
			break;
		case 2:
			sessionMap.put("SearchStatusCode", "16");
			break;
		case 3:
			sessionMap.put("SearchStatusCode", "24");
			break;
		case 4:
			return "PageInvalid";
		}
		return "gotoAttorneyAdditionCaseFilings";
	}
	
	
	
	public String gotoReadyForCourtCaseFilings()
	{
		Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
		System.out.println("==============================================================");
		System.out.println("I have click the first Link for Attorney Ready For court Cases");
		System.out.println("The Format Type selected is : " + sessionMap.get("formatTypeSelected"));
		System.out.println("==============================================================");
		Integer myint = (Integer) sessionMap.get("formatTypeSelected");
		
		
		switch(myint.intValue())
		{
		case 1:
			sessionMap.put("SearchStatusCode", "11");
			break;
		case 2:
			sessionMap.put("SearchStatusCode", "11");
			break;
		case 3:
			sessionMap.put("SearchStatusCode", "10");
			break;
		case 4:
			return "PageInvalid";
		}
		return "gotoReadyForCourtCaseFilings";
	}
	
	
	
	
	public String gotoClerkReceivedCaseFilings()
	{
		Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
		System.out.println("==============================================================");
		System.out.println("I have click the first Link for Clerk Received Cases");
		System.out.println("The Format Type selected is : " + sessionMap.get("formatTypeSelected"));
		System.out.println("==============================================================");
		Integer myint = (Integer) sessionMap.get("formatTypeSelected");
		
		
		switch(myint.intValue())
		{
		case 1:
			sessionMap.put("SearchStatusCode", "1");
			break;
		case 2:
			sessionMap.put("SearchStatusCode", "1");
			break;
		case 3:
			sessionMap.put("SearchStatusCode", "1");
			break;
		case 4:
			return "PageInvalid";
		}
		
		return "gotoClerkreceivedCaseFilings";
	}
	
	
	public String gotoReadyToImportCaseFilings()
	{
		Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
		System.out.println("==============================================================");
		System.out.println("I have click the first Link for Ready to Import Cases");
		System.out.println("The Format Type selected is : " + sessionMap.get("formatTypeSelected"));
		System.out.println("==============================================================");
		Integer myint = (Integer) sessionMap.get("formatTypeSelected");
		
		
		switch(myint.intValue())
		{
		case 1:
			sessionMap.put("SearchStatusCode", "20");
			break;
		case 2:
			sessionMap.put("SearchStatusCode", "20");
			break;
		case 3:
			sessionMap.put("SearchStatusCode", "17");
			break;
		case 4:
			return "PageInvalid";
		}
		return "gotoReadyToImportCaseFilings";
	}
	
	
	
	public String gotoUnsentCaseFilings()
	{
		Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
		System.out.println("==============================================================");
		System.out.println("I have click the first Link for unsent Cases");
		System.out.println("The Format Type selected is : " + sessionMap.get("formatTypeSelected"));
		System.out.println("==============================================================");
		Integer myint = (Integer) sessionMap.get("formatTypeSelected");
		
		
		switch(myint.intValue())
		{
		case 1:
			sessionMap.put("SearchStatusCode", "7");
			break;
		case 2:
			sessionMap.put("SearchStatusCode", "7");
			break;
		case 3:
			sessionMap.put("SearchStatusCode", "12");
			break;
		case 4:
			return "PageInvalid";
		}
		return "gotoUnsentCaseFilings";
	}
	
	
	
	public String gotoUnsentAdditionCaseFilings()
	{
		Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
		System.out.println("==============================================================");
		System.out.println("I have click the first Link for unsent Addition Cases");
		System.out.println("The Format Type selected is : " + sessionMap.get("formatTypeSelected"));
		System.out.println("==============================================================");
		Integer myint = (Integer) sessionMap.get("formatTypeSelected");
		
		
		switch(myint.intValue())
		{
		case 1:
			sessionMap.put("SearchStatusCode", "15");
			break;
		case 2:
			sessionMap.put("SearchStatusCode", "15");
			break;
		case 3:
			sessionMap.put("SearchStatusCode", "13");
			break;
		case 4:
			return "PageInvalid";
		}
		return "gotoUnsentAdditionCaseFilings";
	}
	
	
	public String gotoClerkRejectedCaseFilings()
	{
		Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
		System.out.println("==============================================================");
		System.out.println("I have click the first Link for Clerk Rejected Cases");
		System.out.println("The Format Type selected is : " + sessionMap.get("formatTypeSelected"));
		System.out.println("==============================================================");
		Integer myint = (Integer) sessionMap.get("formatTypeSelected");
		
		
		switch(myint.intValue())
		{
		case 1:
			sessionMap.put("SearchStatusCode", "3");
			break;
		case 2:
			sessionMap.put("SearchStatusCode", "3");
			break;
		case 3:
			sessionMap.put("SearchStatusCode", "3");
			break;
		case 4:
			return "PageInvalid";
		}
		return "gotoClerkrejectedCaseFilings";
	}
	
}
